/*
 *  Copyright 2012 Dirk Vranckaert
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package eu.vranckaert.vvl.service.impl;

import android.content.Context;
import android.graphics.Bitmap;
import android.provider.Settings;
import android.test.AndroidTestCase;
import eu.vranckaert.vvl.exception.ServiceException;
import eu.vranckaert.vvl.model.TrafficInfoGraphicalEnum;
import eu.vranckaert.vvl.service.WebService;
import eu.vranckaert.vvl.utils.context.Constants;
import eu.vranckaert.vvl.utils.context.Preference;

/**
 * User: DIRK VRANCKAERT
 * Date: 27/02/12
 * Time: 11:43
 */
public class WebServiceImplTest extends AndroidTestCase {
    private Context ctx;
    private WebService service;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        ctx = getContext();
        service = new WebServiceImpl(ctx);
    }
    
    public void testDoHtmlGet() {
        try {
            String result = service.doHtmlGet("http://www.google.be");
            assertNotNull("The result should not be null", result);
            assertTrue("The result should contain HTML", result.length() > 0);
        } catch (ServiceException e) {
            fail("An internet connection should be available!");
        }
    }

    public void testGraphicalTrafficImageURL() {
        Preference.removePreference(ctx, Constants.Preferences.Keys.TRAFFIC_INFO_GRAPHICAL_IMAGE_SIZE);

        String url = String.format(TrafficInfoGraphicalEnum.GRAPHICAL_IMAGE_URL,
                Preference.getTrafficInfoGraphicalImageSize(ctx), TrafficInfoGraphicalEnum.Region.FLANDERS, false);
        try {
            Bitmap image = service.doImageGet(url);
            assertNotNull("The image should not be null", image);
        } catch (ServiceException e) {
            fail("There is a problem retrieving the graphical traffic image!");
        }
    }
}